package com.caiden_micheal.dynamic.workflow.mapper;

import com.caiden_micheal.dynamic.workflow.domain.DynamicWorkflow;
import com.caiden_micheal.dynamic.workflow.dto.FindDWorkflowPageQueryDTO;
import com.caiden_micheal.dynamic.workflow.vo.WorkflowSelectDataVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface DWorkflowMapper {
    void insertWorkflow(DynamicWorkflow dynamicWorkflow);

    List<DynamicWorkflow> findDWorkflowByCondition(FindDWorkflowPageQueryDTO findDWorkflowPageQueryDTO);

    Integer findDWorkflowByConditionCount(FindDWorkflowPageQueryDTO findDWorkflowPageQueryDTO);

    @Select("SELECT * FROM sys_dynamic_workflow WHERE id=#{id}")
    DynamicWorkflow findById(Long id);

    void updateWorkflow(DynamicWorkflow dynamicWorkflow);

    @Select("SELECT * FROM sys_dynamic_workflow WHERE display_name=#{displayName}")
    DynamicWorkflow findByDisplayName(String displayName);

    @MapKey("id")
    Map<Long, Map<String, String>> findMapByIdList(@Param("workflowIdList") List<Long> workflowIdList);

    @Select("SELECT * FROM sys_dynamic_workflow WHERE display_name LIKE CONCAT('%',#{displayName},'%') ORDER BY create_time DESC LIMIT 0,20")
    List<WorkflowSelectDataVO> findWorkflowSelectData(String displayName);

    @Delete("DELETE FROM sys_dynamic_workflow WHERE id=#{id}")
    void removeDWorkflow(Long id);
}
